export function html2Text(val) {
  const div = document.createElement('div')
  div.innerHTML = val
  return div.textContent || div.innerText
}

export function dateFormat(time, cFormat) {

}

export function orderStatus(status) {
  let data = {
    "0": "待付款",
    "1": "待发货",
    "2": "待收货",
    "4": "待评论",
    "8": "已评论",
    "16": "已退款",
    "32": "退款处理中",
    "64": "退款失败",
    "99": "已取消"
  };
  return data[status + ''];
}

export function authStatusFilter(status) {
  return {
    '0': '待审核',
    '1': '审核中',
    '2': '审核通过',
    '9': '审核不通过'
  }[status.toString()];
}

export function goodsStatus(status) {
  return ["出售中", "下架区", "仓库中"][parseInt(status)]
}
export function tagStatus(status) {
  if (status == 9) {
    return 'danger';
  }
  return ['success', 'info', 'warning', 'danger'][parseInt(status)];
}

export function absUrl(url) {
  if (!url) {
    return url;
  }
  if (url.indexOf('://') != -1) {
    return url;
  }
  if (url[0] != '/') {
    url = '/' + url;
  }
  if (url.indexOf('/images/') != -1 || url.indexOf('/imgs/') != -1) {
    return url;
  }
  if (url.indexOf('/oss-image/') != -1) {
    return 'http://weixin-ostorage01.oss-cn-shenzhen.aliyuncs.com' + url;
  }
  return 'https://weixina01.bppc.com.cn/zy-admin/UploadFiles/zy/product' + url;
}

export function parseTime(time, cFormat) {
  if (arguments.length === 0) {
    return null
  }

  if ((time + '').length === 10) {
    time = +time * 1000
  }

  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  let date
  if (typeof time === 'object') {
    date = time
  } else {
    date = new Date(parseInt(time))
  }
  const formatObj = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay()
  }
  const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
    let value = formatObj[key]
    if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
    if (result.length > 0 && value < 10) {
      value = '0' + value
    }
    return value || 0
  })
  return time_str
}
